//
//  SearchTableView.m
//  YCSearchDemo
//
//  Created by huyuchen on 2018/3/3.
//  Copyright © 2018年 Hyc. All rights reserved.
//

#import "SearchTableView.h"
#import "TitleTableViewCell.h"
#import "SearchModel.h"

@interface SearchTableView () <UITableViewDelegate, UITableViewDataSource>

@end

@implementation SearchTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SearchModel *model = [self.dataArray objectAtIndexSafe:indexPath.row];
    if ([model isKindOfClass:[SearchModel class]]) {
        TitleTableViewCell *cell = [TitleTableViewCell cellWithInitStyleTableView:self class:[TitleTableViewCell class]];
        cell.title = model.area_name;
        return cell;
    }
    return [UITableViewCell new];
}


//- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id obj = [self.dataArray objectAtIndex:indexPath.row];
    
    if (self.BlockClickCell) {
        self.BlockClickCell(obj);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.f;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}

@end
